home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / GDInfo.c < prev    next >
Text File  |  1995-10-27  |  6KB  |  169 lines

  1. /*
  2. GDInfo.c
  3.  
  4. GDInfo fills the user-supplied VideoInfo record with all the descriptive
  5. information that can be obtained quickly from the driver and GDevice record
  6. without disturbing the screen. Under 1-bit QuickDraw it ignores the card->device
  7. field.
  8.  
  9. GDInfoTime fills the user-supplied VideoInfo record with the results of calling
  10. most of the routines in GDTime.c. Under 1-bit QuickDraw it ignores the "card->device"
  11. argument.
  12.  
  13. HISTORY:
  14. 4/16/93    dgp set pages=1 for 1-bit qd.
  15. 4/26/93    dgp    test HasDepth before relying on it.
  16. 4/27/93    dgp    replaced HasDepth by GDHasMode.
  17. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  18.             Metrowerks CodeWarrior C.
  19. 9/5/94 dgp removed assumption in printf's that int==short.
  20. 10/5/95 dgp added call to GDGestalt() to get full version of video driver if available.
  21. */
  22. #include "VideoToolbox.h"
  23. #include "GDInfo.h"
  24. #if UNIVERSAL_HEADERS<2
  25.     typedef unsigned long UInt32;
  26. #endif
  27.  
  28. OSErr GDInfo(VideoInfo *card)
  29. {
  30.     short pixelSize,pages,d,mode;
  31.     Rect r;
  32.     long qD;
  33.     ColorSpec cSpec;
  34.     char *s;
  35.     
  36.     Gestalt(gestaltQuickdrawVersion,&qD);
  37.     if(qD<gestalt8BitQD){
  38.         card->device=NULL;
  39.         sprintf(card->cardName,"%s","Original 1-bit QuickDraw");
  40.         sprintf(card->driverName,"%s","Original 1-bit QuickDraw");
  41.         for(d=1;d<6;d++)card->depth[d].pixelSize=0;
  42.         card->slot=0;
  43.         CopyQuickDrawGlobals();    // make sure qd is valid.
  44.         r=qd.screenBits.bounds;
  45.         card->width=r.right-r.left;
  46.         card->height=r.bottom-r.top;
  47.         card->depth[0].pixelSize=1;
  48.         card->depth[0].clutSize=2;
  49.         card->depth[0].pages=1;
  50.         card->depth[0].framesPerClutUpdate=NAN;
  51.         card->depth[0].framesPerClutUpdateHighPriority=NAN;
  52.         card->depth[0].framesPerClutUpdateQuickly=NAN;
  53.         card->depth[0].vblPerFrame=1.0;
  54.         card->d=0;
  55.         card->dacSize=1;
  56.         card->dacMask=((1<<card->dacSize)-1)<<(16 - card->dacSize);
  57.         card->basicTested=1;
  58.         return 0;
  59.     }
  60.     if(!card->basicTested){
  61.         // This info never changes, so get it only once
  62.         for(d=0;d<6;d++){
  63.             card->depth[d].pixelSize=0;
  64.             card->depth[d].mode=0;
  65.             card->depth[d].pages=0;
  66.         }
  67.         d=0;
  68.         for(mode=0x80;mode<=0x85 && d<6;mode++){
  69.             if(GDHasMode(card->device,mode,&pixelSize,&pages)){
  70.                 card->depth[d].mode=mode;
  71.                 card->depth[d].pixelSize=pixelSize;
  72.                 card->depth[d].pages=pages;
  73.                 d++;
  74.             }
  75.         }
  76.         sprintf(card->cardName,"%s",s=GDCardName(card->device));
  77.         DisposePtr(s);
  78.         if(GDGestaltIsOn(card->device)){
  79.             char stage[5]="\000dab\000";
  80.             NumVersion numVersion;
  81.             int error;
  82.             
  83.             error=GDGestalt(card->device,'vers',(UInt32 *)&numVersion);
  84.             if(!error)sprintf(card->driverName,"%s %d.%01u%01u"
  85.                 ,GDNameStr(card->device)
  86.                 ,(numVersion.majorRev/16)*10+numVersion.majorRev%16
  87.                 ,numVersion.minorAndBugRev/16,numVersion.minorAndBugRev%16
  88.                 ,stage[numVersion.stage/0x20]);
  89.         }else{
  90.             if(GDVersion(card->device)==0)sprintf(card->driverName,"%s"
  91.                 ,GDNameStr(card->device));
  92.             else sprintf(card->driverName,"%s version %d"
  93.                 ,GDNameStr(card->device),(int)GDVersion(card->device));
  94.         }
  95.         card->slot=GetDeviceSlot(card->device);
  96.         r=(**(**card->device).gdPMap).bounds;
  97.         card->width=r.right-r.left;
  98.         card->height=r.bottom-r.top;
  99.         card->dacSize=GDDacSize(card->device);        // Takes 200 µs.
  100.         card->dacMask=((1<<card->dacSize)-1)<<(16 - card->dacSize);
  101.         card->setEntriesQuickly=(GetCardType(card->device)!=0);
  102.         card->gdGetEntries=(0==GDGetEntries(card->device,0,0,&cSpec));
  103.         card->basicTested=1;
  104.     }
  105.     // d changes any time you call SetDepth, so update it every time.
  106.     for(d=0;d<6;d++)if(card->depth[d].mode==(**card->device).gdMode)card->d=d;
  107.     
  108.     // Collect information from the GDevice record
  109.     card->depth[card->d].pixelSize=(**(**card->device).gdPMap).pixelSize;
  110.     card->depth[card->d].clutSize=GDClutSize(card->device);
  111.     return 0;
  112. }
  113.  
  114. OSErr GDInfoTime(VideoInfo *card)
  115. {
  116.     int error=0;
  117.     short clutSize=0,d=card->d;
  118.     double frames,s,missingFrames,frameRate;
  119.     long qD;
  120.     printf(BLANKLINE);    
  121.     printf("%d-bit pixels: timing CopyBits . . ." "\r",(int)card->depth[d].pixelSize);
  122.     card->depth[d].movieRate=GDMovieRate(card->device,0);
  123.     printf(BLANKLINE);    
  124.     printf("%d-bit pixels: timing CopyBitsQuickly . . ." "\r",(int)card->depth[d].pixelSize);
  125.     card->depth[d].movieRateQuickly=GDMovieRate(card->device,1);
  126.     Gestalt(gestaltQuickdrawVersion,&qD);
  127.     if(qD>=gestalt8BitQD){
  128.         printf(BLANKLINE);    
  129.         printf("%d-bit pixels: timing cscSetEntries . . ." "\r",(int)card->depth[d].pixelSize);
  130.         error=GDTimeClut(card->device,GDSetEntries,clutSize,&s,&frames,&missingFrames,&frameRate);
  131.         if(error){
  132.             // Video driver won't load clut, so we can't time that, but we can still time fram rate.
  133.             frameRate=GDFrameRate(card->device);
  134.         }
  135.         card->depth[d].frameRate=frameRate;
  136.         card->depth[d].vblPerFrame=GDVBLRate(card->device)/frameRate;
  137.         card->depth[d].framesPerClutUpdate=frames;
  138.         card->depth[d].missingFramesPerClutUpdate=missingFrames;
  139.     }else{
  140.         card->depth[d].frameRate=GDFrameRate(NULL);
  141.         card->depth[d].vblPerFrame=1.0;
  142.         card->depth[d].framesPerClutUpdate=NAN;
  143.         card->depth[d].missingFramesPerClutUpdate=NAN;
  144.     }
  145.     if(qD>=gestalt8BitQD){
  146.         printf(BLANKLINE);    
  147.         printf("%d-bit pixels: timing GDSetEntriesByTypeHighPriority . . ." "\r",(int)card->depth[d].pixelSize);
  148.         error=GDTimeClut(card->device,GDSetEntriesByTypeHighPriority,clutSize,&s,&frames,&missingFrames,&frameRate);
  149.         card->depth[d].framesPerClutUpdateHighPriority=frames;
  150.         card->depth[d].missingFramesPerClutUpdateHighPriority=missingFrames;
  151.     }else{
  152.         card->depth[d].framesPerClutUpdateHighPriority=NAN;
  153.         card->depth[d].missingFramesPerClutUpdateHighPriority=NAN;
  154.     }
  155.     if(qD>=gestalt8BitQD && GetCardType(card->device)){
  156.         printf(BLANKLINE);    
  157.         printf("%d-bit pixels: timing SetEntriesQuickly . . ." "\r",(int)card->depth[d].pixelSize);
  158.         error=GDTimeClut(card->device,SetEntriesQuickly,clutSize,&s,&frames,&missingFrames,&frameRate);
  159.         card->depth[d].framesPerClutUpdateQuickly=frames;
  160.         card->depth[d].missingFramesPerClutUpdateQuickly=missingFrames;
  161.     }else{
  162.         card->depth[d].framesPerClutUpdateQuickly=NAN;
  163.         card->depth[d].missingFramesPerClutUpdateQuickly=NAN;
  164.     }
  165.     printf(BLANKLINE);    
  166.     card->timeTested=1;
  167.     card->depth[d].timeTested=1;
  168.     return error;
  169. }